package com.xlb.controller;

import com.xlb.aspect.ApiOperationLog;
import com.xlb.model.vo.notice.*;
import com.xlb.service.AdminNoticeService;
import com.xlb.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 小聋包
 * @date 2024/9/21
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/notice")
@Api(tags = "Admin公告模块")
public class AdminNoticeController {

    @Autowired
    private AdminNoticeService noticeService;

    @PostMapping("/add")
    @ApiOperation(value = "添加公告")
    @ApiOperationLog(description = "添加公告")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response addNotice(@RequestBody @Validated AddNoticeReqVO addNoticeReqVO) {
        return noticeService.addNotice(addNoticeReqVO);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改公告")
    @ApiOperationLog(description = "修改公告")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateNotice(@RequestBody @Validated UpdateNoticeReqVO updateNoticeReqVO) {
        return noticeService.updateNotice(updateNoticeReqVO);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "公告删除")
    @ApiOperationLog(description = "公告删除")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteNotice(@RequestBody @Validated DeleteNoticeReqVO deleteNoticeReqVO) {
        return noticeService.deleteNotice(deleteNoticeReqVO);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询公告分页数据")
    @ApiOperationLog(description = "查询公告分页数据")
    public Response findNoticePageList(@RequestBody @Validated FindNoticePageListReqVO findNoticePageListReqVO) {
        return noticeService.findNoticePageList(findNoticePageListReqVO);
    }

    @PostMapping("/isShow/update")
    @ApiOperation(value = "公告展示状态修改")
    @ApiOperationLog(description = "公告展示状态修改")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateNoticeIsShow(@RequestBody @Validated UpdateNoticeIsShowReqVO updateNoticeIsShowReqVO) {
        return noticeService.updateNoticeIsShow(updateNoticeIsShowReqVO);
    }
}
